﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            List<Model> lst = new List<Model>();
            lst.Add(new Model(2, "phatquy"));
            lst.Add(new Model(110, "long"));
            //listBox1.Items.Add("phatquy");//new Model(2,"phat quy"));
            listBox1.DataSource = lst;
            listBox1.DisplayMember = "Name";
            listBox1.ValueMember = "Id";
        }

        public class Model
        {
            private int id;
            private String name;


            public Model()
            {
            }
            public Model(int _id, String str)
            {
                this.id = _id;
                this.name = str;
            }

            public int Id
            {
                get { return id; }
                set { id = value; }
            }

            public String Name
            {
                get { return name; }
                set { name = value; }
            }
        }


        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
        }

        private void listBox1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(listBox1.SelectedValue.ToString());
        }
    }
}
